package lock.ReentrantLock;

import org.junit.Test;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @describe: 类描述信息
 * @author: morningcat.zhang
 * @date: 2019/4/22 4:38 PM
 */
public class ReentrantLockTest {

    Lock lock = new ReentrantLock();
    Long count = 0L;

    public void addTen() {
        lock.lock();
        try {
            //
            for (int i = 0; i < 1000; i++) {
                count++;
            }
            System.out.println(count);
        } catch (Exception e) {
            //
        }finally {
            lock.unlock();
        }
    }

    public static void main(String[] args) throws InterruptedException {
        ReentrantLockTest obj = new ReentrantLockTest();
        for (int i = 0; i < 10; i++) {
            new Thread(() -> obj.addTen()).start();

        }

        Thread.sleep(1000L);
    }


}
